package Main;

import java.awt.BorderLayout;

import java.awt.Dimension;

import java.awt.Toolkit;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;

import java.awt.event.WindowEvent;
import java.awt.event.WindowStateListener;

import javax.swing.JFrame;
import javax.swing.JScrollPane;

import Greedy_Snake_Map.MMap;
import snake.Snake_body;
public class Main_Frame extends JFrame{
	private static JScrollPane scrollpane;
	private static eastPanel eastpanel;
	private static mainPanel panel;
	private static westPanel westpanel;
	private static Main_Frame frame;
	static public Snake_body snake;
 	public  Main_Frame(Snake_body snake)
 	{
 		
 		super.setTitle("贪吃蛇se");
 		set_panel();
 		frame=this;
 		Main_Frame.snake=snake;
 		this.addWindowStateListener(new WindowStateListener() {
            @Override
            public void windowStateChanged(WindowEvent e) {
                    // 最大化按钮被点击
            		//System.out.println("max");
            	if(e.getNewState()==0)
            	{
            		Dimension newsize =getSize();
         			Dimension eastsize=new Dimension((int)(newsize.getWidth()*(0.2)),(int)(newsize.getHeight()));
         			eastpanel.setPreferredSize(eastsize);
         			westpanel.setPreferredSize(eastsize);
            	}
                	
                
            }
        });
 		this.addComponentListener(new ResizeListener());
 		this.setIconImage(Toolkit.getDefaultToolkit().getImage("img\\1111.jpg"));
 		super.setLocationByPlatform(true);
 		this.setDefaultCloseOperation(EXIT_ON_CLOSE);
 		this.setExtendedState(JFrame.MAXIMIZED_BOTH);//屏幕最大化
 		this.setMinimumSize(new Dimension((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/2),
 				(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/2)));
 		this.setLocation((int)(Toolkit.getDefaultToolkit().getScreenSize().getWidth()/4),
 				(int)(Toolkit.getDefaultToolkit().getScreenSize().getHeight()/4));
 		panel=new mainPanel(snake);
 		
 		scrollpane=new JScrollPane(panel);//把中心面板添加到滚轮条界面里面去
 		
 		scrollpane.getVerticalScrollBar().setPreferredSize(new Dimension(0, 0));//把水平滚轮条隐藏
 		scrollpane.getHorizontalScrollBar().setPreferredSize(new Dimension(0, 0));//把竖直滚轮条隐藏
 		this.add(scrollpane,BorderLayout.CENTER);
 		scrollpane.setPreferredSize(new Dimension(20,20));
 		
 		this.setVisible(true);
 	}
 	public static void Close()
 	{
 		frame.dispose();
 	}
 	public static JScrollPane get_ScrollPane()
 	{
 		return scrollpane;
 	}
 	public  void set_panel()
 	{
 		BorderLayout layoutb=new BorderLayout();
 		this.setLayout(layoutb);
 		eastpanel =new eastPanel();//东边的panel
 		westpanel=new westPanel();//西边的panel
 		makeEastPanel.setButton(eastpanel);
 		
 		this.add(eastpanel, BorderLayout.EAST);
 		this.add(westpanel,BorderLayout.WEST);
 		Dimension newsize =getSize();
		Dimension eastsize=new Dimension((int)(newsize.getWidth()*(0.2)),(int)(newsize.getHeight()));
		eastpanel.setPreferredSize(eastsize);
		westpanel.setPreferredSize(eastsize);
 	}
 	public static mainPanel getpanel()
 	{
 		return panel;
 	}
 	private class ResizeListener extends ComponentAdapter{
 		public void componentResized(ComponentEvent e) {
 			Dimension newsize =getSize();
 			Dimension eastsize=new Dimension((int)(newsize.getWidth()*(0.2)),(int)(newsize.getHeight()));
 			eastpanel.setPreferredSize(eastsize);
 			westpanel.setPreferredSize(eastsize);
 			revalidate();
 		}
 		
 	}
 	
 		
 }
 	


